import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Rectangle {
    id: navigationBar
    
    property int currentIndex: 0
    property var menuItems: [
        { text: "主面板", icon: "🏠", page: "MainDashboard" },
        { text: "设备控制", icon: "⚙️", page: "DeviceControlPage" },
        { text: "定时采样", icon: "⏰", page: "TimedSamplingPage" },
        { text: "定量采样", icon: "📊", page: "VolumeSamplingPage" },
        { text: "用户管理", icon: "👥", page: "UserManagementPage" },
        { text: "操作记录", icon: "📋", page: "OperationRecordsPage" },
        { text: "数据可视化", icon: "📈", page: "DataVisualizationPage" },
        { text: "系统设置", icon: "⚙️", page: "SettingsPage" }
    ]
    
    signal itemClicked(int index, string page)
    
    color: "#2196F3"
    
    ListView {
        id: menuListView
        anchors.fill: parent
        anchors.margins: 5
        
        model: menuItems
        spacing: 2
        
        delegate: Rectangle {
            width: menuListView.width
            height: 50
            radius: 4
            
            color: {
                if (index === currentIndex) return "#1976D2"
                if (mouseArea.containsMouse) return "#1E88E5"
                return "transparent"
            }
            
            Behavior on color {
                ColorAnimation {
                    duration: 150
                }
            }
            
            RowLayout {
                anchors.fill: parent
                anchors.margins: 10
                spacing: 10
                
                Text {
                    text: modelData.icon
                    font.pixelSize: 18
                    color: "white"
                }
                
                Text {
                    text: modelData.text
                    font.pixelSize: 14
                    color: "white"
                    Layout.fillWidth: true
                }
            }
            
            MouseArea {
                id: mouseArea
                anchors.fill: parent
                hoverEnabled: true
                
                onClicked: {
                    currentIndex = index
                    navigationBar.itemClicked(index, modelData.page)
                }
            }
        }
    }
    
    // 底部用户信息
    Rectangle {
        anchors.bottom: parent.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        height: 60
        color: "#1976D2"
        
        Column {
            anchors.centerIn: parent
            spacing: 2
            
            Text {
                text: typeof qmlBridge !== 'undefined' ? qmlBridge.getCurrentUser() : "用户"
                font.pixelSize: 14
                font.bold: true
                color: "white"
                anchors.horizontalCenter: parent.horizontalCenter
            }
            
            Text {
                text: typeof qmlBridge !== 'undefined' ? qmlBridge.getCurrentUserRole() : "角色"
                font.pixelSize: 12
                color: "#E3F2FD"
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }
        
        MouseArea {
            anchors.fill: parent
            onClicked: {
                // 显示用户菜单或退出登录
                if (typeof qmlBridge !== 'undefined') {
                    qmlBridge.logoutUser()
                }
            }
        }
    }
}